﻿using System;
using System.Collections;
using System.Diagnostics;
using Manager;
using Sound;
using UnityEngine;

// Token: 0x0200033A RID: 826
public abstract class LoadAudioBase : AssetLoader
{
	// Token: 0x17000210 RID: 528
	// (get) Token: 0x060014E9 RID: 5353 RVA: 0x000901A8 File Offset: 0x0008E3A8
	// (set) Token: 0x060014EA RID: 5354 RVA: 0x000901B0 File Offset: 0x0008E3B0
	public AudioClip clip { get; private set; }

	// Token: 0x17000211 RID: 529
	// (get) Token: 0x060014EB RID: 5355 RVA: 0x000901BC File Offset: 0x0008E3BC
	// (set) Token: 0x060014EC RID: 5356 RVA: 0x000901C4 File Offset: 0x0008E3C4
	public AudioSource audioSource { get; private set; }

	// Token: 0x060014ED RID: 5357 RVA: 0x000901D0 File Offset: 0x0008E3D0
	public void Init(AudioSource audioSource)
	{
		this.audioSource = audioSource;
		base.transform.SetParent(audioSource.transform, false);
		base.Init();
	}

	// Token: 0x060014EE RID: 5358 RVA: 0x000901F4 File Offset: 0x0008E3F4
	public override IEnumerator _Init()
	{
		if (base.initialized)
		{
			yield break;
		}
		if (this.isAsync)
		{
			yield return base.StartCoroutine(base._Init());
		}
		else
		{
			base.StartCoroutine(base._Init());
		}
		this.clip = (base.loadObject as AudioClip);
		if (this.clip == null)
		{
			if (this.audioSource != null)
			{
				UnityEngine.Object.Destroy(this.audioSource.gameObject);
			}
			else
			{
				UnityEngine.Object.Destroy(base.gameObject);
			}
		}
		yield break;
	}

	// Token: 0x060014EF RID: 5359 RVA: 0x00090210 File Offset: 0x0008E410
	protected IEnumerator Play(GameObject fadeOut, Action<GameObject> get)
	{
		if (this.audioSource.playOnAwake)
		{
			yield break;
		}
		if (this.delayTime > 0f)
		{
			yield return new WaitForSecondsRealtime(this.delayTime);
		}
		while (!this.audioSource.isActiveAndEnabled)
		{
			yield return null;
		}
		if (this.fadeTime > 0f)
		{
			//fadeOut = Sound.PlayFade(fadeOut, this.audioSource, this.fadeTime);
			get.Call(fadeOut);
		}
		else
		{
			this.audioSource.Play();
		}
		if (this.audioSource.loop)
		{
			yield break;
		}
		float endTime = this.audioSource.clip.length - this.audioSource.time;
		if (endTime > 0f)
		{
			yield return new WaitForSecondsRealtime(endTime);
		}
		FadePlayer fadePlay = this.audioSource.GetComponent<FadePlayer>();
		if (fadePlay != null)
		{
			fadePlay.Stop(this.fadeTime);
		}
		else
		{
			UnityEngine.Object.Destroy(this.audioSource.gameObject);
		}
		yield break;
	}

	// Token: 0x060014F0 RID: 5360 RVA: 0x0009023C File Offset: 0x0008E43C
	protected override void OnDestroy()
	{
		base.OnDestroy();
		if (this.isReleaseClip && Singleton<Manager.Sound>.IsInstance())
		{
			Singleton<Manager.Sound>.Instance.Remove(this.clip);
		}
	}

	// Token: 0x060014F1 RID: 5361 RVA: 0x0009026C File Offset: 0x0008E46C
	[Conditional("BASE_LOADER_LOG")]
	private void LogError(string str)
	{
		GlobalData.Debug_LogError(str);
	}

	// Token: 0x0400193A RID: 6458
	public float delayTime;

	// Token: 0x0400193B RID: 6459
	public float fadeTime;

	// Token: 0x0400193C RID: 6460
	public int settingNo = -1;

	// Token: 0x0400193F RID: 6463
	protected bool isReleaseClip = true;
}
